package com.example.sm.mycook.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by Administrator on 2016/12/6.
 */
public class HomeHeadVpAdapter extends PagerAdapter {
    private List<View> list;
    private Context context;

    public HomeHeadVpAdapter(Context context, List<View> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list!=null?list.size():0;
    }

    @Override
    public View instantiateItem(ViewGroup container, int position) {
      View ret=null;
        ret=list.get(position);

        container.addView(ret);

        return  ret;

    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);

        if (object instanceof  View)
        {
            View view= (View) object;
            container.removeView(view);
        }
    }
}
